/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package BusinessLogic;

import DTO.Manager;
import DTO.Zone;
import DataAccess.DataUtility;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

/**
 *
 * @author Tran anh
 * @version 1.0
 */
public class Statistics {

    /**
     * create a vector to contain zones
     */
    private Vector<Zone> listZone;

    /**
     * create a vecotr to contain Manager
     */
    private Vector<Manager> listManager;

    /**
     * load list Manager from database, every Manager must be status = 1
     * @return list Manager
     */
    public Vector<Manager> loadManager() {
        listManager = new Vector<Manager>();
        try {
            ResultSet rs = DataUtility.excuteQuery("Select * from ManagerAccount where status = 1");

            while (rs.next()) {
                Manager manager = new Manager();
                listManager.add(manager);

                manager.setName(rs.getString("Name"));
                manager.setPassWord(rs.getString("PassWord"));
                manager.setPower(rs.getInt("power"));
                manager.setUserName(rs.getString("userName"));
            }
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
        return listManager;
    }

    /**
     * load list zone from database
     * @return list zone
     */
    public Vector<Zone> loadZone() {
        listZone = new ZoneManagement().loadZone();
        return listZone;
    }

    /**
     * get number booth was be rent by Exhibitor has status = 1 and
     * idZone = idZone just pass.
     * @param idZone is identify Booth in that zone
     * @return number booth was be rent
     */
    public int BoothInZone(String idZone) {
        try {
            ResultSet rs = DataUtility.excuteQuery("select count(*) as number from booth where status = 1 and idzone = " + "\'" + idZone + "\'");
            rs.next();
            int numberBooth = rs.getInt("number");
            return numberBooth;

        } catch (SQLException ex) {
            ex.printStackTrace();
            return 0;
        }
    }

    /**
     * get total booth from all zone
     * @return total booth
     */
    public int totalBooth() {
        try {
            ResultSet rs = DataUtility.executeProcedure("TotalBooth", true);
            rs.next();

            return rs.getInt("totalBooth");

        } catch (SQLException ex) {
            ex.printStackTrace();
            return 0;
        }
    }
}
